﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PI_CS_Library.PicsNetwork_Information_Model;
using PI_CS_Library;

namespace PI_CS_GUI
{
    public partial class DelMatrixGUI : Form
    {
        PicsNetworkController _nc;
        GUIDelegate _gui;

        public DelMatrixGUI(PicsNetworkController _nc, GUIDelegate _gui)
        {
            this._nc = _nc;
            this._gui = _gui;
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _gui(this, new GUIArgs("delMatrixCancel"));
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string _name;
            int _matrixId;

            if (textBox1.Enabled)
            {
                _name = textBox1.Text;
                _matrixId = _nc.Network.GetMatrixId(_name);
            }

            else
            {
                _matrixId = Int32.Parse(textBox2.Text);
                if (!_nc.Network.MatrixResourceList.ContainsKey(_matrixId))
                    _matrixId = -1;
            }

            if (_matrixId != -1)
            {
                _nc.Network.RemoveMatrix(_matrixId, _nc, _gui, true);

                this.Close();
            }
            else MessageBox.Show("Error - No matrix with a given name.");
        }

        private void DelMatrixGUI_FormClosing(object sender, FormClosingEventArgs e)
        {
            _gui(this, new GUIArgs("delMatrixCancel"));
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
                textBox2.Enabled = false;
            else
                textBox2.Enabled = true;
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            if (textBox2.Text != "")
                textBox1.Enabled = false;
            else
                textBox1.Enabled = true;
        }
    }
}
